package com.itheima.tlias84.dao.mapper;

import com.itheima.tlias84.controller.po.UpdateDeptParam;
import com.itheima.tlias84.service.dto.SelectAllDeptDTO;
import com.itheima.tlias84.dao.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {

    @Select("select id, name, update_time from dept order by update_time desc")
    List<SelectAllDeptDTO> selectAll();

    @Select("select id, name from dept where id = #{id}")
    SelectAllDeptDTO selectOne(@Param("id") Integer id);

    @Select("select name from dept where id != #{d.id} and name = #{d.name}")
    String selectByName(@Param("d") UpdateDeptParam param);

    @Insert("insert into dept(name, create_time, update_time) values(#{d.name}, #{d.createTime}, #{d.updateTime})")
    int insertDept(@Param("d") Dept dept);

    @Delete("delete from dept where id = #{id}")
    int deleteDept(@Param("id") Integer id);

    @Update("update dept set name=#{d.name}, update_time=#{d.updateTime} where id=#{d.id}")
    int updateDept(@Param("d") Dept dept);

    int batchInsert(@Param("list") List<Dept> list);

    int batchDelete(@Param("list") List<Integer> list);
}
